
class ForgetPwdController {
    constructor($scope,$rootScope,$state,$q,$timeout,UserService) {
        Object.assign(this, {$scope, $rootScope, $state, $q,$timeout, UserService});
        this.new_pwd = null;
        this.question = null;
        this.answer = null;
        this.username = null;
        this.checkNewPassword = null;
        this.routeAterLogout = "login";
        this.questionList = [{name: "你名字是什么？"}]

    }

    forget_pwd_question(){
        let self = this;
        let param = {};
        param.user_name = self.username;
        self.UserService.forget_pwd_question(param).then(_success).catch(_error);
        function _success(data) {
            self.question = data.question;
        }
        function _error(message) {
            console.log(message);
        }
    }

    comfirnResetPwd() {
        let self = this;
        let param = {};
        param.user_name = self.username;
        //param.question = self.question;
        param.answer = self.answer;
        param.new_pwd = self.new_pwd;
        param.confirm_new_pwd = self.checkNewPassword;
        self.UserService.forget_pwd(param).then(_success).catch(_error);
        function _success(data) {
            layer.alert(data.message.content,{
                title:"信息",
                icon: 1,
                btn:["确定"],
                btn1:function (index,layerro) {
                    layer.close(index);
                    self.$state.go("login");
                }
            });
        }
        function _error(reason) {
            let type = typeof reason;
            layer.open({
                   icon:2,
                   title:"错误！",
                   content:type=='object'?reason.text:reason,
                   btn:["好的"],
                   yes:function (index,layerno) {
                       layer.close(index);
                   }
               });
        }

    }
}
ForgetPwdController.$inject = ["$scope","$rootScope", '$state',"$q", '$timeout',"UserService"];

export default ForgetPwdController;